package com.paomi.client.activity.person.presenter;

import com.hannesdorfmann.mosby3.mvp.MvpBasePresenter;
import com.hannesdorfmann.mosby3.mvp.MvpView;
import com.paomi.client.activity.detail.model.CommentListBean;
import com.paomi.client.activity.person.View.MyCommentsView;
import com.paomi.client.activity.person.model.MyCommentBean;
import com.paomi.client.bean.BaseJSON;
import com.paomi.client.net.Api;
import com.paomi.client.net.BaseCallback;
import com.paomi.client.net.Constants;

import java.util.HashMap;
import java.util.Map;

import retrofit2.Call;

public class MyCommentPre extends MvpBasePresenter<MyCommentsView> {
    private MyCommentBean resultGet;
    /**
     * 获取我的评论
     */
    public void getComments(int pageNum) {
        Map<String, String> map = new HashMap<>();
        map.put("pageSize", Constants.PAGE_SIZE + "");
        map.put("pageNum", ""+pageNum);
        Api.getInstanceService(Constants.Ticket_URL).getMyCommentList(map).enqueue(new BaseCallback<MyCommentBean>() {
            @Override
            public void onResponse(Call<MyCommentBean> call, MyCommentBean result) {
                resultGet=result;
                if(isViewAttached())
                getView().showSuccessList(result);
            }
        });
        if(resultGet==null){
            MyCommentBean resultGet=new MyCommentBean();
            getView().showSuccessList(resultGet);
        }
    }

    /**
     * 删除我的评论
     */
    public void deleteCommente(String id, int pos) {
        Api.getInstanceService(Constants.Ticket_URL).deleteComment(id).enqueue(new BaseCallback<BaseJSON>() {
            @Override
            public void onResponse(Call<BaseJSON> call, BaseJSON result) {
                getView().deleteSuccess(result, pos);
            }
        });
    }


}
